﻿package desk.game.eatbean;

import javax.microedition.lcdui.Graphics;

public class Beans {
	static int beans[][]={
			{1,1,1,1,1,1,1,1},
			{1,1,1,1,1,1,1,1},
			{1,1,1,2,2,1,1,1},
			{1,1,1,2,2,1,1,1},
			{1,1,1,2,2,1,1,1},
			{1,1,1,2,2,1,1,1},
			{1,1,1,1,1,1,1,1},
			{1,1,1,1,1,1,1,1}
			};
	private int count=999;
	static int score=0;
	private int width;
	private int height;
	static int time=0;
	private int n;
	static int next=0;
	public Beans()
	{
		for(int i=0;i<8;i++)
			for(int j=0;j<8;j++)
			{
				if(beans[i][j]==0)
				{
					beans[i][j]=1;
				}
			}
		next++;
		score=0;
		time=0;
	}
	public Beans(int width,int height)
	{
		this.width=width;
		this.height=height;
	}
	public void paint(Graphics g)
	{
		for(int i=0;i<8;i++)
			for(int j=0;j<8;j++)
			{
				if(beans[i][j]==1)
					{
						g.setColor(255,255,0);
						g.fillArc(i*20+15, j*20+15, 3, 3, 0, 360);
					}
			}
	}
	public void eat(int x,int y)
	{
		for(int j=0;j<8;j++)
			for(int i=0;i<8;i++)
			{
				if(beans[j][i]==1)
				{
					if((j*20+15)>(x+3)&&(j*20+15)<(x+17)&&(i*20+15)>(y+3)&&(i*20+15)<(y+17))
					{
						beans[j][i]=0;
						score++;
					}
				}
			}
	}
	public void drawScore(Graphics g)
	{
		n++;
		if(n==10)
		{
			time++;
			n=0;
		}
		g.setColor(255,255,255);
		g.drawString("score:"+String.valueOf(score),width,0,Graphics.TOP|Graphics.RIGHT);
		g.drawString("Time:"+String.valueOf(time),0,height,Graphics.LEFT|Graphics.BOTTOM);
		g.drawString("关数:"+String.valueOf(next),width,height,Graphics.RIGHT|Graphics.BOTTOM);
	}
	public int getScore()
	{
		return score;
	}
	public void drawWin(Graphics g)
	{
		count=0;
		for(int j=0;j<8;j++)
			for(int i=0;i<8;i++)
			{
				if(beans[j][i]==1)
				{
					count++;
				}
			}
		if(count==0)
		{
			g.setColor(255,255,255);
			g.drawString("you win!",width/2,height/2,Graphics.BASELINE|Graphics.HCENTER);
		}
	}
	public boolean isWin()
	{
		if(count==0)
		{
			return false;
		}
		return true;
	}
	public int getCount()
	{
		return count;
	}
}
